package top.kaoshanji.q1ch07c;

import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.SortedMap;

/**
 * 代码清单-q1ch07c-346页a：显示字符集和别名
 * author kaoshanji
 * ^_^
 * create time 2025/3/12 18:30
 */
public class AvailableCharSets {

    public static void main(String[] args) {

        SortedMap<String, Charset> charSets = Charset.availableCharsets();
        for (String csName: charSets.keySet()) {
            System.out.print(csName);

            Iterator<String> aliases = charSets.get(csName).aliases().iterator();

            if (aliases.hasNext()) {
                System.out.print(": ");
            }

            while (aliases.hasNext()) {
                System.out.print(aliases.next());
                if (aliases.hasNext()) {
                    System.out.print(", ");
                }
            }

            System.out.println();
        }

    }


}
